﻿Imports Licenta3.Commanding
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Licenta3.Common.Framework

Public Class PolylineObject
    Inherits ObjectBase
    Private _Geometry As New Polyline
    <System.Xml.Serialization.XmlIgnore> Public Property Geometry As Polyline
        Get
            Return _Geometry
        End Get
        Set(value As Polyline)
            _Geometry = value
            _Geometry.Closed = True
            OnPropertyChanged("Geometry")
        End Set
    End Property
    Private _SelectGeometryCommand As ICommand
    <System.Xml.Serialization.XmlIgnore> Public Property SelectGeometryCommand As ICommand
        Get
            Return _SelectGeometryCommand
        End Get
        Set(value As ICommand)
            _SelectGeometryCommand = value
            OnPropertyChanged("SelectImobilCommand")
            'RaiseEvent 
        End Set
    End Property
    Public Sub SelectGeometry()
        Dim dwg As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = dwg.Editor
        Dim db = dwg.Database

        Dim opts As New PromptEntityOptions(vbLf & "Selecteaza o polilinie")
        opts.SetRejectMessage(vbLf & "Musai polilinie!")
        opts.AddAllowedClass(GetType(Polyline), True)

        Dim per As PromptEntityResult = ed.GetEntity(opts)
        Using dl As DocumentLock = dwg.LockDocument(DocumentLockMode.ProtectedAutoWrite, Nothing, Nothing, True)
            If per.Status = PromptStatus.OK Then
                Using tr As Transaction = db.TransactionManager.StartTransaction
                    Dim pl As Polyline = tr.GetObject(per.ObjectId, OpenMode.ForWrite)
                    If pl.Closed = False Then
                        MsgBox("Atentie! Polilinia nu este inchisă și va fi inchisă acum!")
                    End If
                    FormatPolyline(pl)
                    Geometry = pl.Clone
                    tr.Commit()
                End Using
            End If
        End Using
    End Sub
    Public Function canSelectGeometry() As Boolean
        Return True
    End Function

    Public Sub New()
        _SelectGeometryCommand = New DelegateCommand(Of String)(AddressOf SelectGeometry, AddressOf canSelectGeometry)
    End Sub
End Class
